package bTree.LeetCode;

public class 除自身以外数组的乘积 {
    public int[] productExceptSelf(int[] nums) {
        int length = nums.length;
        int[] pre = new int[length];
        int[] pro = new int[length];
        pre[0] = 1;
        pro[length - 1] = 1;
        for (int i = 1; i < length; i++) {
            pre[i] = pre[i - 1] * nums[i - 1];
        }
        for (int i = length - 2; i >= 0; i--) {
            pro[i] = pro[i + 1] * nums[i + 1];
        }
        int[] res = new int[length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = pre[i] * pro[i];
        }
        return res;
    }
}